package nz.ac.massey.cs.se400_2013.ass3;

import java.util.Collection;
import java.util.HashSet;

public class Course implements Visitable {
	private String name = "";
	private Collection<Paper> papers = new HashSet<Paper>();
	
	@Override
	public void accepts(Visitor visitor) {
		for (Paper p:papers) {
			p.accepts(visitor);
		}
		visitor.visit(this);
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public void addPaper(Paper paper){
		if(this.papers.add(paper)){
			paper.addCourse(this);
		}
	}
	
	public void removePaper(Paper paper){
		if(this.papers.remove(paper)){
			paper.removeCourse(this);
		}
	}
	
	public Collection<Paper> getPapers() {
		return papers;
	}
	public void setPapers(Collection<Paper> papers) {
		this.papers = papers;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Course other = (Course) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "Course [name=" + name + "]";
	}
}
